<template>
	<view>
		<cu-custom :bgColor="'bg-' + theme.backgroundColor" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">用户数据</block>
		</cu-custom>

		<scroll-view scroll-y class="scroll" refresher-enabled @refresherrefresh="refresherrefresh"
			@scrolltolower="scrolltolower" scroll-anchoring :style="customBarSty" :lower-threshold="80"
			:refresher-triggered="reftriggered">
			<view class="content p-all24">
				<view class="search">
					<view class="cuIcon-search icon"></view>
					<view class="search-ipt">
						<input type="text" placeholder="请输入用户手机号码查询" v-model="inputKey" confirm-type="search"
							@confirm="keyboardSearch" @keyup.enter="keyboardSearch" />
					</view>
					<view class="search-btn" :class="'bg-' + theme.backgroundColor" @click="keyboardSearch">搜索</view>
				</view>
				<view class="masters-list">
					<view class="item" v-for="(item, index) in tableList" :key="index">
						<view class="top">
							<view class="avatas">
								<image v-if="item.userHeadimgUrl" :src="item.userHeadimgUrl" mode="scaleToFill" />
								<image v-else src="@/static/public/img/user.png" mode="scaleToFill" />
							</view>
							<view class="info">
								<view> {{ item.userName || "微信用户" }} </view>
								<view class="text-666">{{ item.userPhone || "暂无" }}</view>
							</view>
						</view>
						<view class="content">
							<view class="col">
								<view class="form-item">
									<text>直播间数：</text>
									<text class="ml6">{{ item.liveTimes }}</text>
								</view>
								<view class="form-item">
									<text>id：</text>
									<text class="ml6"> {{ item.userId }}</text>
								</view>
							</view>
							<view class="col">
								<view class="form-item">
									<text>答题数：</text>
									<text class="ml6">{{ item.topicNum }}</text>
								</view>
								<view class="form-item">
									<text>答对数：</text>
									<text class="ml6"> {{ item.topicYesNum }}</text>
								</view>
							</view>
							<view class="col">
								<view class="form-item">
									<text>领取红包：</text>
									<text class="ml6 text-price">{{ item.rewardPay || 0 }}</text>
								</view>
								<view class="form-item">
									<text>领取积分数：</text>
									<text class="ml6">{{ item.integralNum || 0 }}</text>
								</view>
							</view>
							<view class="col">
								<view class="form-item">
									<text>领取优惠券数：</text>
									<text class="ml6">{{ item.couponNum }}</text>
								</view>
								<view class="form-item">
									<text>获得奖品数：</text>
									<text class="ml6">{{ item.lotteryNum }}</text>
								</view>
							</view>
							<view class="col">
								<view class="form-item">
									<text>团长昵称：</text>
									<text class="ml6">{{ item.tzUserName }}</text>
								</view>
								<view class="form-item">
									<text>团长电话：</text>
									<text class="ml6">{{ item.tzUserPhone }}</text>
								</view>
							</view>
						</view>
					</view>
					<view :class="'cu-load ' + (loadmore ? 'loading' : 'over')"></view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	const app = getApp();
	import api from "../../../api/api.js";
	import util from "@/utils/util.js";
	export default {
		data() {
			return {
				theme: app.globalData.theme,
				reftriggered: false,
				customBarSty: `height: calc(100vh - ${this.CustomBar}px);`,
				inputKey: "",
				loadmore: false,
				tzUserId: "",
				page: {
					current: 1,
					size: 5,
					total: 0,
				},
				tableList: [],
			};
		},
		onLoad(options) {
			this.tzUserId = options.tzUserId;
			this.page.current = 1;
			this.tableList = [];
			this.getPage();
		},
		methods: {
			getPage(fn) {
				this.loadmore = true;
				let para = {
					...this.page,
					userPhone: this.inputKey,
					tzUserId: this.tzUserId,
				};
				api.pageLiveAndUser(util.filterForm(para)).then((res) => {
					let tableList = res.data.records || [];
					this.tableList.push(...tableList);
					if (tableList.length < this.page.size) {
						this.loadmore = false;
					}
					typeof fn === "function" && fn(res);
				});
			},
			keyboardSearch() {
				this.tableList = [];
				this.page.current = 1;
				this.getPage();
			},
			scrolltolower() {
				if (this.loadmore) {
					this.page.current++;
					this.getPage();
				}
			},
			refresherrefresh(e) {
				this.reftriggered = true;
				this.tableList = [];
				this.page.current = 1;
				this.getPage(() => {
					this.reftriggered = false;
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	.search {
		padding: 10rpx 0rpx 10rpx 32rpx;
		margin-top: 20rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: #fff;
		border-radius: 16rpx;
		font-size: 24rpx;

		.icon {
			margin-right: 20rpx;
		}

		.search-ipt {
			flex: 1;

			input {
				border: none;
				outline: none;
				width: 100%;
				font-size: 28rpx;
				height: 70rpx;
				line-height: 70rpx;
			}
		}

		.search-btn {
			padding: 15rpx 32rpx;
			color: #fff;
			border-radius: 16rpx;
			margin-right: 10rpx;
			font-size: 24rpx;
		}
	}

	.masters-list {
		.item {
			margin: 24rpx 0rpx 0;
			background-color: #fff;
			border-radius: 16rpx;
			padding: 24rpx;

			.top {
				display: flex;
				align-items: center;

				.avatas {
					width: 120rpx;
					height: 120rpx;
					border-radius: 50%;

					image {
						width: 100%;
						height: 100%;
						border-radius: 50%;
					}
				}

				.info {
					margin-left: 36rpx;
					height: 120rpx;
					padding: 16rpx 0;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
				}
			}

			.content {
				margin-top: 32rpx;
				font-size: 24rpx;
				border-top: 2rpx solid #f6f6f6;
				padding-bottom: 32rpx;

				.col {
					display: flex;
					align-items: center;
					margin-top: 16rpx;

					.form-item {
						width: 50%;
						color: #666;
					}
				}
			}

			.menu {
				display: flex;
				align-items: center;
				justify-content: flex-end;
				margin-top: 30rpx;

				.menu-btn {
					font-size: 30rpx;
					padding: 20rpx;
					border-radius: 12rpx;
					margin-left: 20rpx;
					background: #ffffff;
					border-radius: 16rpx;
					border: 2rpx solid #fb2e1b;
					font-size: 28rpx;
					color: #fb2e1b;
				}
			}
		}
	}

	.num {
		display: flex;
		align-items: center;
		justify-content: flex-start;
		margin-top: 32rpx;

		.num-item {
			width: 50%;
			color: #666;
		}
	}

	.text-gary1 {
		color: #666;
	}

	.text-666 {
		color: #666;
	}

	.scroll {
		height: calc(100vh - 94px);
	}
</style>